<?php

namespace app\admin\model;

use think\Config;
use think\Model;

use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Vms\V20200902\VmsClient;
use TencentCloud\Vms\V20200902\Models\SendTtsVoiceRequest;

class VmsClientApi extends Model
{
    public function send($mobile)
    {
     
        // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
        $cred = new Credential(Config::get('site.TencentCloudSecretId'), Config::get('site.TencentCloudSecretKey'));
        // 实例化一个http选项，可选的，没有特殊需求可以跳过
        $httpProfile = new HttpProfile();
        $httpProfile->setEndpoint("vms.tencentcloudapi.com");
    
        // 实例化一个client选项，可选的，没有特殊需求可以跳过
        $clientProfile = new ClientProfile();
        $clientProfile->setHttpProfile($httpProfile);
        // 实例化要请求产品的client对象,clientProfile是可选的
        $client = new VmsClient($cred, "ap-beijing", $clientProfile);
    
        // 实例化一个请求对象,每个接口都会对应一个request对象
        $req = new SendTtsVoiceRequest();
     
        $params = array(
            "TemplateId" => Config::get('site.TencentCloudVmsTemplateId'),
            "CalledNumber" => "+86".$mobile,
            "PlayTimes" => 3,
            "VoiceSdkAppid" => Config::get('site.TencentCloudVmsAppid')
        );
        $req->fromJsonString(json_encode($params));
    
        // 返回的resp是一个SendTtsVoiceResponse的实例，与请求对象对应
        $resp = $client->SendTtsVoice($req);
    
        // 输出json格式的字符串回包
        print_r($resp->toJsonString());
    }

   
}

?>